<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['nc_limit_manage'];?></h3>
      <?php echo $output['top_link'];?>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="admin_form" method="post" action='index.php?act=admin&op=admin_edit&admin_id=<?php echo $output['info']['admin_id'];?>'>
    <input type="hidden" name="form_submit" value="ok" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label><?php echo $lang['admin_index_username'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><?php echo $output['info']['username'];?></td>
          <td class="vatop tips"></td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for="password"><?php echo $lang['admin_edit_admin_pw']; ?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input id="password" name="password" class="txt" type="password"></td>
           <td class="vatop tips"><?php echo $lang['admin_edit_pwd_tip1'];?></td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label for="password2"><?php echo $lang['admin_edit_admin_pw2']; ?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input id="password2" name="password2" class="txt" type="password"></td>
          <td class="vatop tips"></td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label class="validation" for="group_id">所属商家:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
            <select name="merchants_id">
              <option value="">请选择</option>
              <?php foreach((array)$output['merchants'] as $v){?>
                <option value="<?php echo $v['merchant_id'];?>" <?php echo $output['info']['merchant_id'] == $v['merchant_id'] ? 'selected' : ''; ?>><?php echo $v['mc_shop_name'];?></option>
              <?php }?>
            </select>
          </td>
          <td class="vatop tips" style="color:red;font-size: 20px;">*ps:此处信息,属于商家权限组才需要填写!!!</td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label class="validation" for="gadmin_name"><?php echo $lang['gadmin_name'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
          <select name="group_id">
          <?php foreach((array)$output['gadmin'] as $v){?>
          <option <?php if ($v['group_id'] == $output['info']['group_id']) echo 'selected';?> value="<?php echo $v['group_id'];?>"><?php echo $v['group_name'];?></option>
          <?php }?>
          </select>
          </td>
          <td class="vatop tips"><?php echo $lang['admin_add_gid_tip'];?></td>
        </tr>
      </tbody>
      <tfoot>
        <tr class="tfoot">
          <td colspan="2" ><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script>
//按钮先执行验证再提交表单
$(function(){$("#submitBtn").click(function(){
    if($("#admin_form").valid()){
     $("#admin_form").submit();
	}
	});
});
$(document).ready(function(){
	$("#admin_form").validate({
		errorPlacement: function(error, element){
			error.appendTo(element.parent().parent().prev().find('td:first'));
        },
        rules : {
        	password : {
      				minlength: 6,
      				maxlength: 20
          },
          password2 : {
      				minlength: 6,
      				maxlength: 20,
      				equalTo: '#password'
          },
          group_id : {
              required : true
          },
          merchants_id:{
            required : true
          }
        },
        messages : {
        	password : {
    				  minlength: '<?php echo $lang['admin_add_password_max'];?>',
    				  maxlength: '<?php echo $lang['admin_add_password_max'];?>'
          },
          password2 : {
    				  minlength: '<?php echo $lang['admin_add_password_max'];?>',
    				  maxlength: '<?php echo $lang['admin_add_password_max'];?>',
    				  equalTo:   '<?php echo $lang['admin_edit_repeat_error'];?>'
          },
          group_id : {
              required : '<?php echo $lang['admin_add_gid_null'];?>'
          },
          merchants_id:{
            required:'商家不能为空',
          }
        }
	});
});
<?php if($output['admin_info']['merchant_id'] == 0): ?>
$("[name='merchants_id']").change(function(){
  //改变商家获取该商家底下的权限组
  var mc_id = $(this).val();
  $.getJSON("./index.php?act=common&op=getMerchant_group&mc_id=" + mc_id, function(data){
    $obj = $("[name='group_id']");
    $obj.empty();
    $obj.append('<option value="">请选择</option>');
    $obj.nextAll("select").empty();
    $.each(data, function(i,item){
      $obj.append('<option value="'+item.group_id+'">'+item.group_name+'</option>');
    });
  });
})
<?php endif; ?>
</script>